﻿using System;
using System.IO;
using System.Linq;

namespace KTOP.Launcher
{
    class Options
    {
        private readonly string[] _supportedTargets;

        public string HwId { get; set; }
        public string InputFile { get; set; }
    
        public Options(params string[] supportedTargets)
        {
            _supportedTargets = supportedTargets;
        }

        public void PrintUsage()
        {
            Console.Error.WriteLine("Usage: ktop [target id] [input file]");
            Console.Error.WriteLine("Supported targets are: {0}.", string.Join(",", _supportedTargets));
        }

        void Die(string message)
        {
            //Console.WriteLine(message);
            //PrintUsage();
            throw new OptionsException(message);
        }

        public void Parse(string[] args)
        {
            if (args.Length != 2)
            {
                Die("Error in arguments");
            }

            
            if (!_supportedTargets.Contains(args[0]))
            {
                Die("Unsupported homework");
            }

            HwId = args[0];

            if (!File.Exists(args[1]))
            {
                Die("File not found");
            }

            InputFile = args[1];
        }
    }
}
